/**
 * 
 */
package com.biostime.rpc.terminal.util;

import org.springframework.orm.hibernate4.HibernateJdbcException;

import com.biostime.rpc.terminal.ResponseCode;
import com.biostime.rpc.terminal.exception.CommonException;

/**
 * @author Administrator
 *
 */
public class ResponseCodeUtil {

	public static ResponseCode get(Exception e){
		if(e instanceof HibernateJdbcException){
			if(e.getCause().getCause().getMessage().indexOf("ORA-00001") >= 0){
				return ResponseCode.PRIMARY_KEY_FOUND;
			}else if(e.getCause().getCause().getMessage().indexOf("ORA-12899") >= 0){
				return ResponseCode.BEYOUD_COLUMN_MAX_LENGTH;
			}else if(e.getCause().getCause().getMessage().indexOf("ORA-01400") >= 0){
				return ResponseCode.COLUMN_NOT_NULL;
			}
		}else if(e instanceof CommonException){
			return ((CommonException) e).getCode();
		}
		return null;
	}
}
